<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 创建一个空数组
        var a = new Array();
        // 创建长度为4的数组
        var ar = new Array(4);
        // 等价于 var ar1=[2,3]
        var ar1 = new Array(2, 3);
        //   字面量创建一个空数组
        var a1 = [];
        // 创建一个数组
        let arr = ['胡歌', '彭于晏', '赵玉真', 1, 2, 3];
        console.log(arr[0]);
        console.log(arr[1]);
        console.log(arr[3]);
        console.log(arr[2]);
        console.log(arr[4]);
        console.log(arr[5]);
        // console.log(arr[6]);  //undefined
        let arr1 = ['星期1', '星期2', '星期3', '星期4', '星期5', '星期6', '星期7'];
        console.log(arr1.length);
        for (let i = 0; i < arr1.length; i++) {
            console.log(arr1[i]);
        }



        let arr2 = [1, 4, 3, 6, 9, 5, 7, 10, 8]
        let max = arr2[0];
        let min = arr2[0];
        for (let i = 0; i < arr2.length; i++) {
            if (max < arr2[i]) {
                max = arr2[i];
            } else if (min > arr2[i]) {
                min = arr2[i];
            }
        }
        console.log(max, min);


        // 转换为字符串
        let as = ['pink', 'hug', 'zyz']
        let s = '';
        for (let i = 0; i < as.length; i++) {
            s += as[i]
        }
        console.log(s);


        let as2 = ['pink', 'hug', 'zyz']
        as2[0] = 'uuu';//修改元素索引为零的
        // as2='kdf'; 不能直接给数组名字赋值
        console.log(as2);

        let nub = [];
        for (let i = 0; i <= 10; i++) {
            nub[i] = i;
        }
        console.log(nub);

        let nub1 = [2, 3, 8, 9, 10, 4, 1, 7, 6, 5];
        let d = [];
        // 方法一
        // let j=0;
        for (let i = 0; i < nub1.length; i++) {
            if (nub1[i] > 5) {
                // 新数组满足条件加一次 方法一
                //    d[j]=nub1[i];
                //    j++;
                //    方法二
                d[d.length] = nub1[i];
            }
        }
        console.log(d);



        // 去零
        let nub2 = [2, 3, 8, 0, 9, 0, 10, 0, 4, 1, 7, 6, 5];
        let sd = []
        for (let i = 0; i < nub2.length; i++) {
            if (nub2[i] != 0) {
                sd[sd.length] = nub2[i];
            }
        }


        // 反转数组
        let as3 = ['pink', 'hug', 'zyz']
        let sd1 = [];
        for (let i = as3.length - 1; i >= 0; i--) {
            sd1[sd1.length] = as3[i];
        }
        console.log(sd1);


        // instanceof 运算符 判断是否为
        var arrp = [2, 344, 5]
        var obj = { name: 'hhh' }
        console.log(obj instanceof Object);//true
        console.log(arrp instanceof Array);//true
        console.log(obj instanceof Array);//false

        // 判断是否为数组 
        console.log(Array.isArray(arrp));


        
        function rev(arrs) {
            if (arrs instanceof Array) {
                let x = []
                for (let i = arrs.length - 1; i >= 0; i--) {
                    x[x.length] = arrs[i];
                }
                return x;
            } else {
                return '错误格式...';
            }

        }
        
        console.log(rev([1,2,3,4,5,6]));
        console.log(rev(0,0,0));
    </script>
</body>

</html>